package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btnSend;
    private Button btnSendTrafic;
    private MyBroadcastReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


//        receiver = new MyBroadcastReceiver();
//        IntentFilter filter = new IntentFilter();
//        filter.addAction("Weather_Report");
//        filter.addAction("Trafic_Report");
//        registerReceiver(receiver,filter);

        btnSend = findViewById(R.id.btn_send);
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent();
                intent.setAction("Weather_Report");
                intent.putExtra("Weather","Sunny");
                intent.putExtra("Temprature",25);
                sendBroadcast(intent);

            }
        });

        btnSendTrafic=findViewById(R.id.btn_sendtra);
        btnSendTrafic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction("Trafic_Report");
                intent.putExtra("Trafic","堵车");
                intent.putExtra("Time",40);
                sendBroadcast(intent);

            }
        });
    }
}
